package com.tgky.ybzb.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.web.bind.annotation.*;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import com.tgky.ybzb.entity.XdzyWx;
import com.tgky.ybzb.service.IXdzyWxService;
import com.tgky.ybzb.common.IdParam;
import com.tgky.ybzb.common.PageParam;
import com.tgky.ybzb.common.Result;
import com.tgky.ybzb.utils.MPUtil;

import java.util.List;

/**
 * 卫星表 前端控制器
 *
 * @author XYP
 * @since 2024-07-22
 */
@RestController
@AllArgsConstructor
@Slf4j
@Api(value = "卫星表", tags = "卫星表接口")
@RequestMapping("xdzy-wx")
public class XdzyWxController {

	private IXdzyWxService xdzyWxService;

	/**
	 * 新增
	 */
	@PostMapping("/save")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "新增", notes = "传入xdzyWx")
	public Result save(@RequestBody XdzyWx xdzyWx) {
		if(xdzyWx == null){
			return Result.error("参数异常");
		}
		return Result.status(xdzyWxService.save(xdzyWx));
	}

	/**
	 * 修改 卫星表
	 */
	@PostMapping("/update")
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "修改", notes = "传入xdzyWx")
	public Result update(@RequestBody XdzyWx xdzyWx) {
		if(xdzyWx == null){
			return Result.error("参数异常");
		}
		return Result.status(xdzyWxService.updateById(xdzyWx));
	}

	/**
	 * 删除 卫星表
	 */
	@PostMapping("/remove")
	@ApiOperationSupport(order = 3)
	@ApiOperation(value = "删除", notes = "传入ids")
	public Result remove(@RequestBody IdParam<Long> idParam) {
		if(idParam == null){
			return Result.error("参数异常！");
		}

		return Result.status(xdzyWxService.removeByIds(idParam.getIds()));
	}

	/**
	 * 详情
	 */
	@GetMapping("/detail")
	@ApiOperationSupport(order = 4)
	@ApiOperation(value = "详情", notes = "传入id")
	public Result<XdzyWx> detail(Long id) {
		if(id == null){
			return Result.error("参数异常");
		}
		XdzyWx detail = xdzyWxService.getById(id);
		return Result.successData(detail);
	}

	/**
	 * 查询 卫星表
	 */
	@GetMapping("/list")
	@ApiOperationSupport(order = 5)
	@ApiOperation(value = "查询", notes = "传入xdzyWx")
	public Result list(PageParam pageParam, XdzyWx xdzyWx) {
		List<XdzyWx> list = xdzyWxService.list(xdzyWxService.getQueryWrapper(pageParam, xdzyWx));
		return Result.successData(list);
	}

	/**
	 * 分页 卫星表
	 */
	@GetMapping("/page")
	@ApiOperationSupport(order = 6)
	@ApiOperation(value = "分页", notes = "传入xdzyWx")
	public Result<IPage> page(PageParam pageParam, XdzyWx xdzyWx) {
		IPage<XdzyWx> pages = xdzyWxService.page(
				MPUtil.getPage(pageParam),
				xdzyWxService.getQueryWrapper(null, xdzyWx)
		);
		return Result.successData(pages);
	}

}
